package cn.wolfcode.qo;

import lombok.Getter;

import java.util.List;

@Getter
public class PageResult<T> {

    /* 当前页 */
    private int currentPage;
    /* 每页显示条数 */
    private int pageSize;
    /* 数据 */
    private List<T> data;
    /* 总条数 */
    private int totalCount;
    /*****************************************/
    /* 上一页 */
    private int prevPage;
    /* 下一页 */
    private int nextPage;
    /* 总页数 */
    private int totalPage;

    public PageResult(int currentPage, int pageSize, List<T> data, int totalCount) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.data = data;
        this.totalCount = totalCount;

        /* 总数据只有一页 */
        if(totalCount <= pageSize){
            this.totalPage = 1;
            this.prevPage = 1;
            this.nextPage = 1;
            return;
        }

        this.totalPage = this.totalCount % this.pageSize == 0 ?
                this.totalCount/this.pageSize :
                this.totalCount/this.pageSize + 1;

        this.prevPage = this.currentPage - 1 <= 1 ? 1 : this.prevPage - 1;
        this.nextPage = this.currentPage + 1 >= this.totalPage ? this.totalPage : this.currentPage + 1;

    }
}
